package com.example.spinning.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.spinning.bean.DailyReport;
import com.example.spinning.bean.PaginationResult;
import com.example.spinning.mapper.DailyReportMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Date;
import java.util.List;


@Service
@Transactional
public class DailyReportService {
    @Autowired
    DailyReportMapper dailyReportMapper;


    //增加操作
    public int addNewDailyReport(DailyReport dailyReport) {
        return dailyReportMapper.addNewDailyReport(dailyReport);
    }

    //删除操作
    public boolean deleteDailyReportById(Long[] ids) {
        int result = dailyReportMapper.deleteDailyReportById(ids);
        return result == ids.length;
    }

    //查询并分页
    public PaginationResult<DailyReport> findPage(Integer page, Integer size, String workshop, Date date, Long num,String name) {

        QueryWrapper<DailyReport> wrapper = new QueryWrapper();
        if (null!=workshop)
            wrapper.eq("workshop", workshop);
        if (null!=date)
            wrapper.eq("date", date);
        if (null!=num)
            wrapper.eq("num", num);
        if (null!=name)
            wrapper.eq("name", name);

        Page<DailyReport> pages = new Page<>(page,size);
        dailyReportMapper.selectPage(pages, wrapper);
        int total = dailyReportMapper.selectCount(wrapper);
        List<DailyReport> list = pages.getRecords();

        PaginationResult<DailyReport> pr = new PaginationResult<>();
        pr.setTotal(total);
        pr.setList(list);
        return pr;
    }

    //动态修改
    public int updateCategoryById(DailyReport dailyReport){
        int result = dailyReportMapper.updateById(dailyReport);
        return result;
    }




}




